using System;
using System.Collections;
using System.Drawing;

using needle.UI.Controls.Flat.Windows.Docking;
using needle.UI.Controls.Flat.Windows.Forms;

namespace needle.UI.Controls.Flat.Windows.Forms.Collections
{
    public class TargetCollection : CollectionBase
    {
		private int _suspendCount; 

		public event CollectionClearEventHandler Clearing;
		public event CollectionClearEventHandler Cleared;
		public event CollectionChangeEventHandler Inserting;
		public event CollectionChangeEventHandler Inserted;
		public event CollectionChangeEventHandler Removing;
		public event CollectionChangeEventHandler Removed;
		
		#region Constructors	

		public TargetCollection()
		{
			_suspendCount = 0;
		}

		#endregion

		#region Overrides
	
		protected override void OnClear()
		{
			if (!IsSuspended)
			{
				if (Clearing != null)
					Clearing(this,new EventArgs());
			}
		}	

		protected override void OnClearComplete()
		{
			if (!IsSuspended)
			{
				if (Cleared != null)
					Cleared(this,new EventArgs());
			}
		}	

		protected override void OnInsert(int index, object value)
		{
			if (!IsSuspended)
			{
				if (Inserting != null)
                    Inserting(value, new needle.UI.Controls.Flat.Windows.Forms.Collections.CollectionChangeEventArgs(index));
			}
		}

		protected override void OnInsertComplete(int index, object value)
		{
			if (!IsSuspended)
			{
				if (Inserted != null)
                    Inserted(value, new needle.UI.Controls.Flat.Windows.Forms.Collections.CollectionChangeEventArgs(index));
			}
		}

		protected override void OnRemove(int index, object value)
		{
			if (!IsSuspended)
			{
				if (Removing != null)
                    Removing(value, new needle.UI.Controls.Flat.Windows.Forms.Collections.CollectionChangeEventArgs(index));
			}
		}

		protected override void OnRemoveComplete(int index, object value)
		{
			if (!IsSuspended)
			{
				if (Removed != null)
                    Removed(value, new needle.UI.Controls.Flat.Windows.Forms.Collections.CollectionChangeEventArgs(index));
			}
		}

		#endregion

		#region Methods
		
		public void CopyTo(TargetCollection array, System.Int32 index)
		{
			foreach (Target obj in base.List)
				array.Add(obj);
		}
		
		public Target Add(Target value)
        {
            base.List.Add(value as object);
            return value;
        }

        public void AddRange(Target[] values)
        {
            foreach(Target page in values)
                Add(page);
        }

        public void Remove(Target value)
        {
            base.List.Remove(value as object);
        }

        public void Insert(int index, Target value)
        {
            base.List.Insert(index, value as object);
        }

        public bool Contains(Target value)
        {
            return base.List.Contains(value as object);
        }

        public int IndexOf(Target value)
        {
            return base.List.IndexOf(value);
        }

        public Target Contains(Point pt)
        {
            foreach(Target t in base.List)
            {
                if (t.HotRect.Contains(pt))
                    return t;
            }

            return null;
        }

		#endregion

		#region Properties

		public bool IsSuspended
		{
			get { return (_suspendCount > 0); }
		}

		public Target this[int index]
		{
			get { return (base.List[index] as Target); }
		}

		#endregion
    }
}
